/*******************************************************************************
**
** Copyright (c) 2011 - The OWE Team
**
** This file is part of OWE.
**
** OWE is a free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; version
** version 2.1 of the License.
**
** OWE is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with OWE. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <owe/node.h>
#include <owe/preferenceelement.h>
#include <owe/ustring.h>

OWE_USE_NAMESPACE

/*!
    \class PreferenceElement
    \brief Widget preferences data.

    \ingroup Configuration

    Implementation of the preference element as specified
    <a href="http://www.w3.org/TR/widgets/#preference">here</a>.
*/

/*!
    \fn UString PreferenceElement::name() const

    Returns the preference <a href="http://www.w3.org/TR/widgets/#name2">
    name</a>. This attribute is mandatory and a preference without name is
    considered invalid.
*/

/*!
    \fn UString PreferenceElement::value() const

    Returns the preference <a href="http://www.w3.org/TR/widgets/#value0">
    value</a>.
*/

/*!
    \fn UString PreferenceElement::readOnly() const

    Returns whenever the preference value can be overwritten in run-time.
    Defaults to true as <a href="http://www.w3.org/TR/widgets/#readonly">
    specified</a>.
*/

/*!
    Constructs a new PreferenceElement from a given \a node.
*/
PreferenceElement::PreferenceElement(const Node *node)
    : Element(node, Element::Preference)
    , m_name(node->attribute("name"))
    , m_value(node->attribute("value"))
    , m_readOnly(node->attribute("readonly"))
{
    if (m_readOnly.size() == 0)
        m_readOnly = UString("false");
}

/*!
    Destructs the object releasing all allocated resources.
*/
PreferenceElement::~PreferenceElement()
{
}

/*!
    Returns whenever a preference is considered valid. To be valid, the
    preference must have a name.
*/
bool PreferenceElement::isValid() const
{
    return (m_name.size() > 0);
}
